package com.xkstream.client.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xkstream.client.R;
import com.xkstream.client.entity.Gift;
import com.xkstream.client.entity.ReceiveGift;
import com.xkstream.client.utils.AsyncImage;
import com.xkstream.client.utils.DateUtil;

import java.util.List;

/**
 * Created by admin on 2017/3/28.
 */

public class TodayGiftRankAdapter extends BaseAdapter {
    private Context context;
    private List<ReceiveGift> gifts;

    public TodayGiftRankAdapter(Context context, List<ReceiveGift> gifts) {
        this.context = context;
        this.gifts = gifts;
    }

    @Override
    public int getCount() {
        return gifts.size();
    }

    @Override
    public Object getItem(int position) {
        return gifts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.layout_todaygiftrank_item,null);
            holder.tvSenderName = (TextView)convertView.findViewById(R.id.tvSenderName);
            holder.ivGiftImg = (ImageView)convertView.findViewById(R.id.ivGiftImg);
            holder.tvGiftNum = (TextView)convertView.findViewById(R.id.tvGiftNum);
            holder.tvTime = (TextView)convertView.findViewById(R.id.tvTime);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        ReceiveGift gift = gifts.get(position);
        holder.tvSenderName.setText(gift.getS_nickname());
        holder.tvGiftNum.setText("X"+gift.getGift_number());
        holder.tvTime.setText(DateUtil.getHourAndMinuteStringDate(gift.getGift_time()));
       AsyncImage.loadPhoto(context,gift.getGift_logo(),holder.ivGiftImg);
        return convertView;
    }


    private class ViewHolder {
        TextView tvSenderName;
        ImageView ivGiftImg;
        TextView tvGiftNum;
        TextView tvTime;
    }
}
